#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QtSql/QtSql>
#include <QSqlDatabase>
#include <QSqlQuery>
#include <QTimer>
#include <QDataWidgetMapper>
#include <QtCharts/QtCharts>
#include <QDesktopServices>
#include <QUrl>

QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

private slots:
    void on_pushButton_clicked();
    void on_timer_0_timeout();
    void on_timer_1_timeout();
    void on_pushButton_6_clicked();
    void on_currentRowChanges(const QModelIndex &current, const QModelIndex &previous);
    void on_currentRowChanges_3(const QModelIndex &current, const QModelIndex &previous);
    void on_currentRowChanges_4(const QModelIndex &current, const QModelIndex &previous);
    void on_currentRowChanges_5(const QModelIndex &current, const QModelIndex &previous);
    void on_currentRowChanges_6(const QModelIndex &current, const QModelIndex &previous);
    void on_pushButton_7_clicked();
    void on_lineEdit_textChanged(const QString &arg1);
    void on_pushButton_9_clicked();
    void on_pushButton_5_clicked();
    void on_pushButton_8_clicked();
    void on_cnt_begin_valueChanged(int arg1);
    void on_cnt_end_valueChanged(int arg1);
    void on_pushButton_3_clicked();
    void on_input_id_textChanged(const QString &arg1);
    void on_buy_num_valueChanged(int arg1);
    void on_comboBox_discrete_currentTextChanged(const QString &arg1);
    void on_pushButton_10_clicked();
    void on_pushButton_14_clicked();
    void on_tabWidget_currentChanged(int index);
    void on_pushButton_12_clicked();
    void on_comboBox_currentIndexChanged(int index);
    void on_radioAscend_clicked();
    void on_radioDescend_clicked();
    void on_radioButton_clicked();
    void on_radioButton_2_clicked();
    void on_pushButton_2_clicked();
    void on_lineEdit_5_textChanged(const QString &arg1);
    void on_pushButton_16_clicked();
    void on_pushButton_17_clicked();
    void on_pushButton_18_clicked();
    void on_pushButton_19_clicked();
    void on_pushButton_20_clicked();
    void on_comboBox_4_currentTextChanged(const QString &arg1);
    void on_radioButton_5_clicked();
    void on_radioButton_6_clicked();
    void on_comboBox_5_currentTextChanged(const QString &arg1);
    void on_radioButton_7_clicked();
    void on_radioButton_8_clicked();
    void on_PieHighlight(bool show);
    void on_go2web_clicked();
    void on_lineEdit_3_textChanged(const QString &arg1);
    void on_pushButton_4_clicked();
    void setBackground();
    void resizeEvent(QResizeEvent* event);
    void on_bad_cnts_valueChanged(int arg1);
    void on_mytriggerdata_textChanged(const QString &arg1);

    void on_pushButton_15_clicked();

private:
    Ui::MainWindow *ui;
    QSqlDatabase db;
    QSqlQuery query;
    QTimer *timer_0,*time_1;
    qint8 second;   //用来计数的秒
    QSqlRelationalTableModel *tabMaterials,*tabOrder;
    QSqlTableModel *tabDiscrete,*tabSuppliers,*tabType,*tabEmail,*tabTrigger;
    QItemSelectionModel *theSelection,*theSelection_2,*theSelection_3,*theSelection_4,*theSelection_5,*theSelection_6;
    QDataWidgetMapper *dataMapper,*dataMapper_3,*dataMapper_4,*dataMapper_5,*dataMapper_6,*dataMapper_7;
    int last_index;
    bool stop_select_flag;
private:
    void open_table();
    void table_sort(QSqlTableModel *model,int index);
    double calculate_cost(int id,int num);
    int min_id(QString id,QString table,QString state);
    void input_item(int row,int num,int id,QString name,double money);
    int get_row(QSqlTableModel *model,int column,QString data);
    void type_count();
    void sup_pay();
    void create_table();
    void push_up();
};
#endif // MAINWINDOW_H5
